package com.ruoyi.bom.controller;

import com.ruoyi.bom.domain.SysDept;
import com.ruoyi.bom.domain.TqlFood;
import com.ruoyi.bom.domain.TqlShopFoodCategory;
import com.ruoyi.bom.service.SysDeptService;
import com.ruoyi.bom.service.TqlFoodCategoryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @Author: Jzh
 * @Date: 2024-01-20  21:23
 */
@RestController
@Api(tags = "菜品分类管理")
@RequestMapping("/foodCategory")
public class TqlFoodCategoryController extends BaseController {

    @Autowired
    private SysDeptService sysDeptService;
    @Autowired
    private TqlFoodCategoryService tqlFoodCategoryService;


    /**
     * 产品类别列表
     * @param tqlFood
     * @return
     */
    @RequiresPermissions("bom:foodCategory:list")
    @GetMapping("/list")
    public TableDataInfo list(TqlShopFoodCategory tqlFood){
        LoginUser user= SecurityUtils.getLoginUser();
        SysUser sysUser=user.getSysUser();
        SysDept dept=sysDeptService.selectDeptById(sysUser.getDeptId());
        // SysDept dept=sysUser.getDept();
        String deptCode=dept.getDeptCode();
        String shopId=sysDeptService.getEnabledHllShopIdByKingdeeFnumber(deptCode);
        tqlFood.setShopId(Long.parseLong(shopId));
        List<TqlShopFoodCategory> list = tqlFoodCategoryService.selectFoodCategoryList(tqlFood);
        return getDataTable(list);
    }


    @RequiresPermissions("bom:foodCategory:updateFlag")
    @PostMapping("/updateFlag")
    public AjaxResult updateFlag(@RequestBody TqlShopFoodCategory tqlFood){
        LoginUser user= SecurityUtils.getLoginUser();
        SysUser sysUser=user.getSysUser();
        tqlFood.setUpdateTime(new Date());
        tqlFood.setUpdateBy(sysUser.getUserId());
        return toAjax(tqlFoodCategoryService.updateFlag(tqlFood));
    }


    @RequiresPermissions("bom:foodCategory:import")
    @PostMapping("/import")
    public AjaxResult importFoodCategory(){
        LoginUser user=SecurityUtils.getLoginUser();
        SysUser sysUser=user.getSysUser();
        SysDept dept=sysDeptService.selectDeptById(sysUser.getDeptId());
        // SysDept dept=sysUser.getDept();
        String deptCode=dept.getDeptCode();
        String shopId=sysDeptService.getEnabledHllShopIdByKingdeeFnumber(deptCode);
        return toAjax(tqlFoodCategoryService.importFoodCategory(shopId));
    }


}
